import 'package:flutter/material.dart';

//* 地区的实体类
class District {
  String name;
  List<String> address;
  String id;
  double packagingFactor;
  double deliveryFactor;

  District({this.name, this.address, this.id, this.packagingFactor,
      this.deliveryFactor});

  // 静态方法， 将调用后台接口返回的json格式数据转换为District实体对象
  District.fromJson(Map<String, dynamic> json) {
    address = json['addresses'] != null ? json['addresses'].map<String>((o) => o.toString()).toList():null;
    deliveryFactor = json['deliveryFactor'].toDouble();
    packagingFactor = json['packagingFactor'].toDouble();
    id = json['id'];
    name = json['name'];
  }

  Map toJson() {
    Map _data = {};
    _data['addresses'] = address.map((e) => e = "\"" +e+ "\"").toList();
    _data['deliveryFactor'] = deliveryFactor;
    if(this.id != "") {
      _data['id'] = "\"" + id + "\"";
    }
    _data['name'] =  "\"" + name + "\"" ;
    _data['packagingFactor'] = packagingFactor;
    return _data;
  }
}